<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>addStudentHealth</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{layui/css/layui.css}"  media="all">
    <link rel="stylesheet" th:href="@{css/public.css}" media="all">
    <style>
        body {
            background-color:#FFFFFF;
        }
    </style>
</head>
<body>
<div class="layuimini-main">

    <div class="layui-form layuimini-form">
        <div class="layui-form-item">
            <label class="layui-form-label required">用户账号(学号)</label>
            <div class="layui-input-block">
                <input type="text" name="susername" lay-verify="required" lay-reqtext="账号（学号）不能为空" placeholder="请输入账号（学号）" value="" class="layui-input">
                <!--<tip>填写自己管理账号</tip>-->
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label required">姓名</label>
            <div class="layui-input-block">
                <input type="text" name="sname" lay-verify="required" lay-reqtext="姓名不能为空" placeholder="请输入姓名" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label required">体温</label>
            <div class="layui-input-block">
                <input type="number" name="temperature" lay-verify="required" lay-reqtext="体温不能为空" placeholder="请输入体温(数字)" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item"> <!-- 注意：这一层元素并不是必须的 -->
            <label class="layui-form-label required">打卡日期：</label>
            <div class="layui-input-block">
                <input type="text" name="date" lay-verify="required"  class="layui-input" id="dateSelect">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label required">打卡地区</label>
            <div class="layui-input-block">
                <input type="text" name="area" lay-verify="required" lay-reqtext="打卡地区不能为空" placeholder="请输入打卡地区" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </div>
</div>

<!--时间选择器-->
<!--<script>
    layui.use('laydate', function(){
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#dateSelect' //指定元素
        });
    });
</script>-->
<script th:src="@{lib/layui-v2.5.5/layui.js}" charset="utf-8"></script>
<script th:src="@{layui/layui.js}" charset="utf-8"></script>
<script type="text/javascript" src="layui/jquery.min.js"></script>


<script>
    layui.use(['form', 'table','laydate'], function () {
        var form = layui.form,
            layer = layui.layer,
            table = layui.table,
            $ = layui.$;

            var laydate = layui.laydate;

            //执行一个laydate实例
            laydate.render({
                elem: '#dateSelect' //指定元素
            });
        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();

        // 当前弹出层，防止ID被覆盖
        var parentIndex = layer.index;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            console.log(data);
            var datas = data.field;

            //向后端发送数据并进行添加操作
            $.ajax({
                url:"studentHealth/addStudentHealthSubmit",
                type: "POST",
                data:datas,
                success:function(result){
                    //将json对象转成string
                    // result = JSON.parse(result);
                    if(result.code==200){
                        layer.msg("添加成功！",{
                            icon:6,
                            time:500
                        },function(){
                            parent.window.location.reload();//重新加载页面
                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(iframeIndex);
                        });
                    }else{
                        layer.msg("添加失败！");
                    }
                }
            })

            // var index = layer.alert(JSON.stringify(data.field), {
            //     title: '最终的提交信息'
            // }, function () {
            //
            //     // 关闭弹出层
            //     layer.close(index);
            //     layer.close(parentIndex);
            //
            // });


            return false;
        });

    });
</script>



</body>
</html>